package com.dogstudio.mygame.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

import com.dogstudio.mygame.base.App;

/**
 * Created by Administrator on 2016/8/19 0019.
 */

public class AppUtils {

    public static int getScreenWidth(Context context) {
        final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        final Display display = windowManager.getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getMetrics(displayMetrics);
        boolean isPortrait = displayMetrics.widthPixels < displayMetrics.heightPixels;
        return isPortrait ? displayMetrics.widthPixels
                : displayMetrics.heightPixels;
    }

    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }


    public static int getCardSize(Context context) {
        int screenWidth = getScreenWidth(context);
        int padding = dip2px(context, 10);
        return (screenWidth - 7 * padding) / 4;
    }

    public static int getPanelSize(Context context) {
        return getCardSize(context) * 4 + 5 * dip2px(context, 10);
    }


    private static Toast mToast;

    public static void showTip(String msg) {
        if (mToast == null) {
            mToast = new Toast(App.getInstance());
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.setText(msg);
        mToast.show();
    }

}
